package com.moli.iov.down.command.codec.encode.data;

import com.moli.iov.down.model.dto.remoting.CommandDto;
import com.moli.iov.util.ByteArrayUtil;
import com.moli.iov.util.StringUtil;
import org.apache.commons.lang.ArrayUtils;

/**
 * <p>
 *  终端参数查询命令  0xD8
 * </p>
 *
 * @author: zql
 * @Date: 2018/11/28 09:58
 */
public class ParameterQueryDataEncoder extends BaseEncoder implements DataEncoder {

    @Override
    public byte[] encode(CommandDto commandDto) {
        byte[] all = getByteBuf(commandDto);

        //查询参数总数 n
        all = ArrayUtils.addAll(all, new byte[]{ByteArrayUtil.toByte(commandDto.getParameterIds().size())});
        //参数id
        for(int i = 0; i < commandDto.getParameterIds().size(); i++){
            all = ArrayUtils.addAll(all, StringUtil.hexStringToByte(commandDto.getParameterIds().get(i)));
        }

        return all;
    }
}
